package com.sbtr.common;

/**
 * rest接口返回 实体
 * 
 * @author oujh5
 *
 * @param <T>
 */
public class Response<T> {

	private boolean success;
	private int status;
	private String msg;
	private T data;

	public Response() {
	}

	public Response(boolean success, int status, String msg, T data) {
		this.success = success;
		this.status = status;
		this.msg = msg;
		this.data = data;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static <S> Response<S> success(String msg, S data) {
		return new Response<>(true, ResultCodeCanstant.OK.getValue(), msg, data);
	}

	public static <S> Response<S> success(S data) {
		return new Response<>(true, ResultCodeCanstant.OK.getValue(), "执行成功", data);
	}

	public static <S> Response<S> error(int status, String msg) {
		return new Response<>(false, status, msg, null);
	}

	public static <S> Response<S> error(int status, String msg, S data) {
		return new Response<>(false, status, msg, data);
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
}
